package com.kkwrite.regimen.provider.controller.module;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kkwrite.regimen.common.entity.dto.OutDTO;
import com.kkwrite.regimen.common.entity.dto.module.ModuleDTO;
import com.kkwrite.regimen.provider.exception.ServiceException;
import com.kkwrite.regimen.provider.service.module.ModuleService;

/** 
 * 模块服务
 *
 * @author Soosky Wang
 * @date 2018年7月23日 上午9:38:30 
 * @version 1.0.0
 */
@RestController
@RequestMapping("/module")
public class ModuleController {

	private static final Logger logger = LoggerFactory.getLogger(ModuleController.class);
	
	@Resource(name = "moduleService")
	private ModuleService moduleService;
	
	@GetMapping("/getmodule/{moduleId}")
	public OutDTO getModule(@PathVariable Long moduleId) {
		if (logger.isDebugEnabled()) {
			logger.debug("ModuleController.getModule(), moduleId = {}", moduleId);
		}
		
		OutDTO outDTO = new OutDTO("true", "");
		try {
			ModuleDTO<?> moduleDTO = moduleService.getModuleContent(moduleId);
			
			outDTO.setData(moduleDTO);
			
			return outDTO;
		} catch (ServiceException e) {
			e.printStackTrace();
			return new OutDTO("false", e.getMessage());
		}
	}
	
}
